-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement custom functions. Resolves #13. #44
Conversation
1 similar comment
blinged_args = ['$' + arg for arg in argspec.args] | ||
signature = '{0}({1})'.format(func_name, ', '.join(blinged_args)) | ||
custom_function_list.append((signature.encode('UTF-8'), func)) | ||
return custom_function_list |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better if there is a type for custom function. The type could have explicit fields about sass function: its name, parameter names, and an arbitrary callable. It also could have a method that returns its signature string. I wonder what’s your thought about this idea.
I don’t think data types have to be defined in a separated module. They could be placed in sass.py together. |
return super(SassWarning, cls).__new__(cls, msg) | ||
|
||
|
||
class SassMap(dict): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it good idea to subclass dict
to define a immutable mapping type? How about subclassing collections.Mapping
?
Anyway I really appreciate you! It would be the killer feature of the next release. |
I'll respond all at once instead of a bunch of comments so it's easier:
|
I'm having a really hard time debugging the windows errors :( It would seem it only happens in release mode as well so I lose most of the debugger symbols. |
def _immutable(self, *_): | ||
raise TypeError('SassMaps are immutable.') | ||
|
||
__setitem__ = __delitem__ = _immutable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these _immutable
/__setitem__
/__delitem__
methods don’t have to be overridden anymore, because they actually aren’t defined by collections.Mapping
! It is immutable by default, and there’s collections.MutableMapping
instead for additional mutability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I thought these were better error messages, I can remove however
I am almost with you. For ease of use I think we can make def func_name():
pass
# The most general form: passing a set of SassFunctions.
# It can take any kind of callables, but pretty verbose.
compile(
custom_functions={ # I just suggest this more general parameter name instead
SassFunction('func_name', (), func_name)
}
)
# Less general, but easier-to-use form: passing a mapping.
# Although it cannot take any kind of callables, it can take any kind of *functions*
# defined using `def`/`lambda` syntax.
# It cannot take callables other than them since inspecting arguments is not
# always available for every kind of callables.
compile(
custom_functions={
'func_name': lambda: ...
}
)
# Not general, but the easiest-to-use form for *named* functions:
# passing a set of named functions.
# It can take only named functions which mean defined using `def`.
# It cannot take lambdas since names are unavailable for them.
compile(
custom_functions={func_name}
) |
That's a lot of complexity imo. I can take a stab at it however |
Okay, so let’s keep the current implementation. How about the parameter name I suggested? |
Name works for me, I'll change it :) |
So I've determined the windows issue is actually a problem with upstream. Would it be acceptable to simply disable the error-handling tests under windows? |
1 similar comment
That would be fine if it’s marked as |
1 similar comment
\o/ I got windows to pass \o/ one stupid compile flag was missing >.< |
1 similar comment
Thanks for you again. 😄 |
Implement custom functions. Resolves #13.
I am going to release the next version (probably 0.7.0) which includes this. |
Thanks! |
So Yelp only really needs custom functions for strings, but I decided to implement all of the types.
This is my first attempt at writing CPython code so I'm probably doing a bunch of things wrong. Advice would be great here :)
I had a lot of fun writing this and took a lot of inspiration from https://github.com/sass/perl-libsass/blob/master/lib/CSS/Sass.xs